#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

int main(void)
{
    int fd[2], n;
    pid_t childpid;
    char string[] = "this is pipe data\n";
    char buffer[80];

    pipe(fd);

    if ((childpid = fork()) == -1)
    {
        perror("fork error");
        exit(1);
    }

    if (childpid == 0)
    {
        // child proc closes up input side of pipe
        //close(fd[0]);

        write(fd[1], string, (strlen(string)+1));
        /*close(0);
        dup(fd[0]);
        execlp("sort", "sort", NULL);*/

        exit(0);
    }
    else
    {
        // child closes up out side of pipe
        close(fd[1]);
        n = read(fd[0], buffer, sizeof(buffer));
        printf("received: %s", buffer);
    }

    return 0;
}

